#!/bin/zsh
#docker run -itd --name hsakdahskdhjhaskhdjkash simon-webui-image:v1 /bin/bash
#docker cp  hsakdahskdhjhaskhdjkash:/root/workspace  ./
#docker rm  -f hsakdahskdhjhaskhdjkash
# 定义文件夹路径
FOLDER_PATH="workspace/apps"

# 检查文件夹是否存在
if [ -d "$FOLDER_PATH" ]; then
    echo "文件夹已存在，正在删除..."
    rm -rf "$FOLDER_PATH"  # 删除文件夹及其内容
fi

# 创建新的文件夹
mkdir -p "$FOLDER_PATH"
echo "新文件夹已创建: $FOLDER_PATH"


cat <<EOF >  workspace/main.py
# -*- coding: utf-8 -*-
# @Time:    2025-04-11 17:03
# @Author:  simon
# @Email:   yonglonggeng@163.com
# @WeChat:  ddgetget
# @File:    main.py
# @Project: dev-tools
# @Package:
# @Ref:

from fastapi import FastAPI
import gradio as gr
import uvicorn

app = FastAPI()
from apps.demo import demo

app = gr.mount_gradio_app(app, demo, '/demo')

@app.get('/')
async def hello_world():
    return {'hello': 'world'}

# 启动 FastAPI 应用
if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=80, reload=True)

EOF


cat <<EOF >  workspace/apps/__init__.py
# -*- coding: utf-8 -*-
# @Time:    2025-04-24 17:39
# @Author:  simon
# @Email:   yonglonggeng@163.com
# @WeChat:  ddgetget
# @File:    __init__.py.py
# @Project: dev-tools
# @Package:
# @Ref:
EOF


cat <<EOF >  workspace/apps/demo.py
# -*- coding: utf-8 -*-
# @Time:    2025-04-24 17:40
# @Author:  simon
# @Email:   yonglonggeng@163.com
# @WeChat:  ddgetget
# @File:    demo.py
# @Project: dev-tools
# @Package:
# @Ref:
import os

import gradio as gr

with gr.Blocks() as demo:
    gr.Label("Hello")
    file_names = os.listdir("apps")
    file_names.remove('__init__.py')
    try:
        file_names.remove('__pycache__')
    except:
        pass

    md_conten = ""
    for file_name in file_names:
        md_conten += f"""- [{file_name.split(".")[0]}](/{file_name.split(".")[0]}) \r\n"""
    gr.Markdown(value=md_conten)

if __name__ == '__main__':
    demo.launch()
EOF